package codeTop;

public class q165 {
    public int compareVersion(String version1, String version2) {
        String[] split1 = version1.split("\\.");
        String[] split2 = version2.split("\\.");
        int idx = 0;
        while (idx < split1.length && idx < split2.length) {
            String s1 = split1[idx];
            for (int i = 0; i < s1.length(); i++) {
                if (s1.charAt(i) != '0') {
                    s1 = s1.substring(i);
                    break;
                }
            }
            String s2 = split2[idx];
            for (int i = 0; i < s2.length(); i++) {
                if (s2.charAt(i) != '0') {
                    s2 = s2.substring(i);
                    break;
                }
            }
            int value1 = Integer.parseInt(s1);
            int value2 = Integer.parseInt(s2);
            if (value2 > value1) {
                return -1;
            } else if (value2 < value1) {
                return 1;
            }
            idx++;
        }
        while (idx < split1.length) {
            String s = split1[idx];
            for (int i = 0; i < s.length(); i++) {
                if (s.charAt(i) != '0') {
                    return 1;
                }
            }
            idx++;
        }
        while (idx < split2.length) {
            String s = split2[idx];
            for (int i = 0; i < s.length(); i++) {
                if (s.charAt(i) != '0') {
                    return -1;
                }
            }
            idx++;
        }
        return 0;
    }
}
